package ruc.grs.ypytd.service;

import java.sql.Connection;
import java.util.List;

import org.apache.commons.dbutils.DbUtils;

import ruc.grs.ypytd.dao.StudentDao;
import ruc.grs.ypytd.entity.Student;
import ruc.grs.ypytd.neoutil.CommonService;

public class StudentService extends CommonService {

	public Student login(String userName, String password) {
		Connection connection = null;

		try {
			// connection = OracleDataSource.getConnection();
			StudentDao studentDao = new StudentDao(connection);

			List<Student> students = studentDao.getStudents(userName, password);

			if (students == null || students.size() != 1) {
				return null;
			} else {
				return students.get(0);
			}

		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			try {
				DbUtils.close(connection);
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
	}
}
